<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_AjaxSearchDocAction extends m_backoffice_extends_Action
{
	public function execute()
	{
        $query = $this->getRequestParameter('q');

        if(strlen($query) >= 1)
        {
            $docSearch = $this  ->getDocumentProvider()
                                ->loadDocuments($this->getRequestParameter('model'))
                                ->orLike('document_label', $query.'%')
                                ->orIsEqual('document_uid', $query)
                                ->retrieveDocuments($this->getRequestParameter('lang'));

            if(count($docSearch) > 0)
            {
                foreach($docSearch as $doc)
                {
                    echo $doc."\r\n";
                }
            }
        }
	}	
	
	public function errorHandler()
	{
		return null;
	}
}